<% include header %>
<div class="wap">
  <%if(typeof locals.session.user.email == "undefined"){%>
  <div class="tip">即将推出帐号冲值功能，为了确保你的帐号安全，请填写邮箱地址，用于找回密码、重要安全功能。<a href="/user/account">马上去补全吧！</a></div>
  <%}%>
  <% if (!error) {%>
  <% for(var i = 0;i < group.length; i++){ var orders = group[i];%>
  <div id="shop-<%=orders.shop._id%>">
    <h1 class="page-title">
      <strong><a href="/shop/<%=orders.shop._id%>"><%=orders.shop.name%></a> </strong>
      <span class="shop_tel">电话：<%=orders.shop.tel%></span>
      <span class="shop_address">地址：<%=orders.shop.address%></span>
      <%if(orders.minLuck.user_name){%>
      <span style="float: right;">目测，由 <strong><%=orders.minLuck.user_name%></strong>喂人民服务</span>
      <%}%>
    </h1>
    <section class="main clearfix" style="margin-bottom: 20px">
      <section class="inner">
        <table id="today-list" class="today-tb data" cellpadding="0" cellspacing="0">
          <thead>
          <tr>
            <th class="name">姓名</th>
            <th class="food">订单明细</th>
            <th class="total">应付</th>
            <th class="random">运气值</th>
            <th class="payStatus">订单状态</th>
          </tr>
          </thead>
          <tbody>
          <% orders.orders.forEach(function(order){ %>
          <tr data-id="<%=order._id%>">
            <td class="name user-<%=order.user_id%>"><%=order.user_name%></td>
            <td class="food">
              <ul>
                <% order.order.forEach(function(food){ %>
                <li><%=food.name%> - <%=food.price%>元 - <%=food.num%> 份</li>
                <%})%>
              </ul>
            </td>
            <td class="total">￥<%=order.total%></td>
            <td class="luck" data-luck="<%=order.luck%>">
              <div class="bar" style="width:<%=order.luck*0.9%>px"><%=order.luck%></div>
            </td>
            <td>
              <% if(order.canceled){ %>
              <span class="text-error">已取消</span>
              <% } else if (order.payStatus === "paid") { %>
              <span>已支付</span>
              <% } else if(order.user_name == locals.session.user.name){%>
              <a href="/pay/item?order_id=<%= order._id %>" class="cancel-order">支付</a> |
              <a href="/user/order/delete/<%= order._id %>" class="cancel-order">取消</a>
              <% } else {%>
              <span>未支付</span>
              <% } %>
            </td>
          </tr>
          <%})%>
          </tbody>
          <tfoot>
          <tr style="text-align: right;background: #f9f9f9;">
            <td colspan="6">
              共计：<b><%=orders.totalPrice%></b> 元
            </td>
          </tr>
          </tfoot>
        </table>
        <table id="today-analytics" class="today-tb data">
          <thead>
          <tr>
            <th>订餐统计清单</th>
          </tr>
          </thead>
          <tbody>
          <% for(var key in orders.analytics){%>
          <tr>
            <td><%=orders.analytics[key].name%> - <%=orders.analytics[key].num%>份</td>
          </tr>
          <%}%>
          </tbody>
          <tfoot>
          <tr style="text-align: right;background: #f9f9f9;">
            <td colspan="3">
              <p>共计 <b><%=orders.totalNum%></b> 份， <b><%=orders.totalPrice%></b> 元</p>
            </td>
          </tr>
          </tfoot>
        </table>
        <div class="clearfix"></div>
      </section>
    </section>
  </div>
  <%}}else{%>
  <div class="main inner today_null">
    <div class="txt">
      <h3>大家还没点餐</h3>

      <p>可能大伙太忙了，赶紧去群里吼一声，大家快来餐库<a href="/">点餐</a>啊！</p>
    </div>
  </div>
  <%}%>
</div>
<% include footer %>